package com.controller;

import com.dto.BookDTO;
import com.dto.BookRecommendDTO;
import com.service.BookRecommendServiceImpl;
import com.service.BookServiceImpl;
import com.service.LoginServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linyukun
 * @date 2022/8/1 18:06
 */
@RequestMapping("bookRecommend")
@RestController
public class BookRecommendController {
    @Autowired
    private BookRecommendServiceImpl bookRecommendServiceImpl;

    @Autowired
    private LoginServiceImpl loginServiceImpl;

    /**
     * 获取图书推荐列表
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/getBookRecommendList",method = RequestMethod.POST)
    public Result getBookRecommendList(){
        try{
            loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(bookRecommendServiceImpl.getBookRecommendList());
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 添加图书推荐
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/addBookRecommend",method = RequestMethod.POST)
    public Result addBookRecommend(@RequestBody BookRecommendDTO dto){
        try{
            loginServiceImpl.isLogin();
            return ResultUtil.returnDataSuccess(bookRecommendServiceImpl.addBookRecommend(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

    /**
     * 图书推荐
     * @author linyukun
     * @date 2022-07-09 10:36
     */
    @RequestMapping(value="/deleteBookRecommendById",method = RequestMethod.POST)
    public Result deleteBookRecommendById(@RequestBody BookRecommendDTO dto){
        try{
            String userName = loginServiceImpl.isLogin();
            dto.setDeleteUser(userName);
            return ResultUtil.returnDataSuccess(bookRecommendServiceImpl.deleteBookRecommendById(dto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }

}
